<!DOCTYPE html>
<html>
<head lang="en">
    <meta charset="UTF-8">
    <title>简单的服务器请求</title>
    <script type="text/javascript">
        var xmlobj;
        //创建ActiveXObject 对象 XMLHTTPRequest对象
        function CreateXMLHTTPRequest(){
            if(window.ActionXObject){
                xmlobj = new ActiveXObject("Microsoft.XMLHTTP");
            }else{
                xmlobj = new XMLHttpRequest();
            }
        }

        //处理过程
        function Req(){
            CreateXMLHTTPRequest();
            xmlobj.onreadystatechange = StatHandler;
            xmlobj.open("GET","test.txt",true);
            xmlobj.send(null);
        }

        function StatHandler(){
            if(xmlobj.readyState == 4 && xmlobj.status ==200){
                alert(xmlobj.responseText);
            }
        }
    </script>
</head>
<body>
<form action="">
    <input type="button" value="Request" onclick="Req();" />
</form>
</body>
</html>